/*
 * Trace Recorder for Tracealyzer v4.9.2
 * Copyright 2023 Percepio AB
 * www.percepio.com
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * The ThreadX specific parts needed by the trace recorder
 */

#ifndef TRC_KERNEL_PORT_H
#define TRC_KERNEL_PORT_H

#include <trcRecorder.h>
#include <tx_api.h>
#include <tx_trace.h>
#include "trcKernelPortHooks.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @def TRC_USE_TRACEALYZER_RECORDER
 * @brief Enables/Disables the recorder.
 */
#define TRC_USE_TRACEALYZER_RECORDER 1

/**
 * @def TRACE_KERNEL_VERSION
 * @brief This defines the kernel version/identity.
 */
#define TRACE_KERNEL_VERSION 0xEAAE

/**
 * @def TRC_PLATFORM_CFG
 * @brief This defines the basis for version specific lookup of
 * platform configuration files. If left empty the default
 * RTOS XML files are used.
 */
#define TRC_PLATFORM_CFG "ThreadX"

/**
 * @def TRC_PLATFORM_CFG_MAJOR
 * @brief Major release version for recorder.
 */
#define TRC_PLATFORM_CFG_MAJOR 1

/**
 * @def TRC_PLATFORM_CFG_MINOR
 * @brief Minor release version for recorder.
 */
#define TRC_PLATFORM_CFG_MINOR 1

/**
 * @def TRC_PLATFORM_CFG_PATCH
 * @brief Patchlevel release version for recorder.
 */
#define TRC_PLATFORM_CFG_PATCH 0

/**
 * @def TRACE_CPU_CLOCK_HZ
 * @brief Trace CPU clock speed in Hz.
 */
#define TRACE_CPU_CLOCK_HZ TRC_CFG_CPU_CLOCK_HZ

/**
 * @def TRC_TICK_RATE_HZ
 * @brief Trace RTOS tick rate in Hz.
 */
#define TRC_TICK_RATE_HZ TX_TIMER_TICKS_PER_SECOND

/**
 * @def TraceKernelPortTaskHandle_t
 * @brief RTOS data type for tasks/threads.
 */
#define TraceKernelPortTaskHandle_t TX_THREAD

extern TraceHeapHandle_t xSystemHeapHandle;

#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC)
#error "Dynamic allocation mode isn't supported for ThreadX, there is no system heap to allocate from. Use custom allocation mode to map trace buffer to your own heap."

/**
 * @internal Kernel port specific heap initialization
 */
#define TRC_KERNEL_PORT_HEAP_INIT(size)

/**
 * @internal Kernel port specific heap malloc definition
 */
#define TRC_KERNEL_PORT_HEAP_MALLOC(size) TX_NULL
#endif /* (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC) */

/**
 * @brief A structure representing the kernel port buffer.
 */
typedef struct TraceKernelPortDataBuffer	/* Aligned */
{
	uint8_t buffer[sizeof(TraceHeapHandle_t) + sizeof(TraceKernelPortTaskHandle_t)];
} TraceKernelPortDataBuffer_t;

/**
 * @internal Kernel port initialize callback.
 *
 * This function is called by the recorder as part of its initialization phase.
 *
 * @param[in] pxBuffer Buffer
 * @retval TRC_FAIL Initialization failed
 * @retval TRC_SUCCESS Success
 */
traceResult xTraceKernelPortInitialize(TraceKernelPortDataBuffer_t* pxBuffer);

/**
 * @brief Kernel port begin callback.
 *
 * This function is called by the recorder as part of its begin phase.
 *
 * @retval TRC_FAIL Enabling failed
 * @retval TRC_SUCCESS Success
 */
traceResult xTraceKernelPortEnable(void);

/**
 * @brief Get unused stack size for kernel port thread.
 *
 * @param[in] pvThread Thread
 * @param[out] puxUnusedStack Unused stack
 * @retval TRC_FAIL Failed to get size
 * @retval TRC_SUCCESS Success
 */
traceResult xTraceKernelPortGetUnusedStack(void* pvThread, TraceUnsignedBaseType_t* puxUnusedStack);

/**
 * @brief Get kernel port system heap handle.
 *
 * @return TraceHeapHandle_t
 */
TraceHeapHandle_t xTraceKernelPortGetSystemHeapHandle(void);

/**
 * @brief Get kernel port scheduler suspended state
 *
 * @retval 0 Scheduler not suspended
 * @retval 1 Scheduler suspended
 */
unsigned char xTraceKernelPortIsSchedulerSuspended(void);

/**
 * @brief Sets a name for Queue objects for display in Tracealyzer.
 *
 * @param[in] object Pointer to the Queue that shall be named
 * @param[in] name Name to set (const string literal)
 */
void vTraceSetQueueName(void* object, const char* name);

/**
 * @brief Sets a name for Semaphore objects for display in Tracealyzer.
 *
 * @param[in] object Pointer to the Seamaphore that shall be named
 * @param[in] name Name to set (const string literal)
 */
void vTraceSetSemaphoreName(void* object, const char* name);

/**
 * @brief Sets a name for Mutex objects for display in Tracealyzer.
 *
 * @param[in] object Pointer to the Mutex that shall be named
 * @param[in] name Name to set (const string literal)
 */
void vTraceSetMutexName(void* object, const char* name);

/**
 * @brief Sets a name for Event Group objects for display in Tracealyzer.
 *
 * @param[in] object Pointer to the Event Group that shall be named
 * @param[in] name Name to set (const string literal)
 */
void vTraceSetEventGroupName(void* object, const char* name);

/**
 * @brief Sets a name for Stream Buffer objects for display in Tracealyzer.
 *
 * @param[in] object Pointer to the Stream Buffer that shall be named
 * @param[in] name Name to set (const string literal)
 */
void vTraceSetStreamBufferName(void* object, const char* name);

/**
 * @brief Sets a name for Message Buffer objects for display in Tracealyzer.
 *
 * @param[in] object Pointer to the Message Buffer that shall be named
 * @param[in] name Name to set (const string literal)
 */
void vTraceSetMessageBufferName(void* object, const char* name);


/* Event codes - should match the offline config file. */
#define PSF_EVENT_NULL_EVENT										0

#define PSF_EVENT_TRACE_START										1
#define PSF_EVENT_TS_CONFIG											2
#define PSF_EVENT_OBJ_NAME											3
#define PSF_EVENT_DEFINE_ISR										7

#define PSF_EVENT_STATEMACHINE_STATE_CREATE							0
#define PSF_EVENT_STATEMACHINE_CREATE								0
#define PSF_EVENT_STATEMACHINE_STATECHANGE							0
#define PSF_EVENT_MALLOC											0
#define PSF_EVENT_MALLOC_FAILED 									0
#define PSF_EVENT_FREE												0
#define PSF_EVENT_FREE_FAILED 										0
#define PSF_EVENT_INTERVAL_CHANNEL_CREATE							0
#define PSF_EVENT_INTERVAL_CHANNEL_SET_CREATE						0
#define PSF_EVENT_INTERVAL_CREATE									0
#define PSF_EVENT_INTERVAL_STATECHANGE								0
#define PSF_EVENT_INTERVAL_CHANNEL_CREATE							0
#define PSF_EVENT_INTERVAL_CHANNEL_SET_CREATE						0
#define PSF_EVENT_INTERVAL_START									0
#define PSF_EVENT_INTERVAL_STOP										0
#define PSF_EVENT_TASK_DELETE										PSF_EVENT_THREAD_DELETE_SUCCESS
#define PSF_EVENT_COUNTER_CREATE									0
#define PSF_EVENT_COUNTER_CHANGE									0
#define PSF_EVENT_COUNTER_LIMIT_EXCEEDED							0
#define PSF_EVENT_EXTENSION_CREATE									0
#define PSF_EVENT_HEAP_CREATE										0

#define PSF_EVENT_IFE_NEXT											0
#define PSF_EVENT_IFE_DIRECT										0

/**
 * 0000-999  Default ThreadX Codes
 * 1000-1999 Tz Segment 1
 * 2000-2999 Tz Segment 2
 * 3000-3999 Tz Segment 3
 * 4000-4095 Tz Internal
 */
#define PSF_EVENT_S1_OFFSET 1000
#define PSF_EVENT_S2_OFFSET 2000
#define PSF_EVENT_S3_OFFSET 3000

#define PSF_EVENT_BLOCK_ALLOCATE_SUCCESS							TX_TRACE_BLOCK_ALLOCATE + PSF_EVENT_S2_OFFSET
#define PSF_EVENT_BLOCK_ALLOCATE_FAILED								TX_TRACE_BLOCK_ALLOCATE + PSF_EVENT_S3_OFFSET
#define PSF_EVENT_BLOCK_ALLOCATE_BLOCKED							TX_TRACE_BLOCK_ALLOCATE
#define PSF_EVENT_BLOCK_ALLOCATE_TIMEOUT							TX_TRACE_BLOCK_ALLOCATE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BLOCK_POOL_CREATE_SUCCESS							TX_TRACE_BLOCK_POOL_CREATE
#define PSF_EVENT_BLOCK_POOL_CREATE_FAILED							TX_TRACE_BLOCK_POOL_CREATE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BLOCK_POOL_DELETE_SUCCESS							TX_TRACE_BLOCK_POOL_DELETE
#define PSF_EVENT_BLOCK_POOL_DELETE_FAILED							TX_TRACE_BLOCK_POOL_DELETE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BLOCK_POOL_INFO_GET_SUCCESS						TX_TRACE_BLOCK_POOL_INFO_GET
#define PSF_EVENT_BLOCK_POOL_INFO_GET_FAILED						TX_TRACE_BLOCK_POOL_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BLOCK_POOL_PERFORMANCE_INFO_GET_SUCCESS			TX_TRACE_BLOCK_POOL_PERFORMANCE_INFO_GET
#define PSF_EVENT_BLOCK_POOL_PERFORMANCE_INFO_GET_FAILED			TX_TRACE_BLOCK_POOL_PERFORMANCE_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BLOCK_POOL__PERFORMANCE_SYSTEM_INFO_GET_SUCCESS	TX_TRACE_BLOCK_POOL__PERFORMANCE_SYSTEM_INFO_GET
#define PSF_EVENT_BLOCK_POOL__PERFORMANCE_SYSTEM_INFO_GET_FAILED	TX_TRACE_BLOCK_POOL__PERFORMANCE_SYSTEM_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BLOCK_POOL_PRIORITIZE_SUCCESS						TX_TRACE_BLOCK_POOL_PRIORITIZE
#define PSF_EVENT_BLOCK_POOL_PRIORITIZE_FAILED						TX_TRACE_BLOCK_POOL_PRIORITIZE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BLOCK_POOL_RELEASE_SUCCESS						TX_TRACE_BLOCK_RELEASE
#define PSF_EVENT_BLOCK_POOL_RELEASE_FAILED							TX_TRACE_BLOCK_RELEASE + PSF_EVENT_S1_OFFSET

#define PSF_EVENT_BYTE_ALLOCATE_SUCCESS								TX_TRACE_BYTE_ALLOCATE + PSF_EVENT_S2_OFFSET
#define PSF_EVENT_BYTE_ALLOCATE_FAILED								TX_TRACE_BYTE_ALLOCATE + PSF_EVENT_S3_OFFSET
#define PSF_EVENT_BYTE_ALLOCATE_BLOCKED								TX_TRACE_BYTE_ALLOCATE
#define PSF_EVENT_BYTE_ALLOCATE_TIMEOUT								TX_TRACE_BYTE_ALLOCATE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BYTE_POOL_CREATE_SUCCESS							TX_TRACE_BYTE_POOL_CREATE
#define PSF_EVENT_BYTE_POOL_CREATE_FAILED							TX_TRACE_BYTE_POOL_CREATE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BYTE_POOL_DELETE_SUCCESS							TX_TRACE_BYTE_POOL_DELETE
#define PSF_EVENT_BYTE_POOL_DELETE_FAILED							TX_TRACE_BYTE_POOL_DELETE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BYTE_POOL_INFO_GET_SUCCESS						TX_TRACE_BYTE_POOL_INFO_GET
#define PSF_EVENT_BYTE_POOL_INFO_GET_FAILED							TX_TRACE_BYTE_POOL_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BYTE_POOL_PERFORMANCE_INFO_GET_SUCCESS			TX_TRACE_BYTE_POOL_PERFORMANCE_INFO_GET
#define PSF_EVENT_BYTE_POOL_PERFORMANCE_INFO_GET_FAILED				TX_TRACE_BYTE_POOL_PERFORMANCE_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BYTE_POOL__PERFORMANCE_SYSTEM_INFO_GET_SUCCESS	TX_TRACE_BYTE_POOL__PERFORMANCE_SYSTEM_INFO_GET
#define PSF_EVENT_BYTE_POOL__PERFORMANCE_SYSTEM_INFO_GET_FAILED		TX_TRACE_BYTE_POOL__PERFORMANCE_SYSTEM_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BYTE_POOL_PRIORITIZE_SUCCESS						TX_TRACE_BYTE_POOL_PRIORITIZE
#define PSF_EVENT_BYTE_POOL_PRIORITIZE_FAILED						TX_TRACE_BYTE_POOL_PRIORITIZE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_BYTE_POOL_RELEASE_SUCCESS							TX_TRACE_BYTE_RELEASE
#define PSF_EVENT_BYTE_POOL_RELEASE_FAILED							TX_TRACE_BYTE_RELEASE + PSF_EVENT_S1_OFFSET

#define PSF_EVENT_FLAGS_CREATE_SUCCESS                 				TX_TRACE_EVENT_FLAGS_CREATE
#define PSF_EVENT_FLAGS_CREATE_FAILED								TX_TRACE_EVENT_FLAGS_CREATE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_FLAGS_DELETE_SUCCESS								TX_TRACE_EVENT_FLAGS_DELETE
#define PSF_EVENT_FLAGS_DELETE_FAILED								TX_TRACE_EVENT_FLAGS_DELETE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_FLAGS_GET_SUCCESS                   			  	TX_TRACE_EVENT_FLAGS_GET + PSF_EVENT_S2_OFFSET
#define PSF_EVENT_FLAGS_GET_FAILED									TX_TRACE_EVENT_FLAGS_GET + PSF_EVENT_S3_OFFSET
#define PSF_EVENT_FLAGS_GET_BLOCKED									TX_TRACE_EVENT_FLAGS_GET
#define PSF_EVENT_FLAGS_GET_TIMEOUT									TX_TRACE_EVENT_FLAGS_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_FLAGS_INFO_GET_SUCCESS          		 	    	TX_TRACE_EVENT_FLAGS_INFO_GET
#define PSF_EVENT_FLAGS_INFO_GET_FAILED								TX_TRACE_EVENT_FLAGS_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_FLAGS_PERFORMANCE_INFO_GET_SUCCESS				TX_TRACE_EVENT_FLAGS_PERFORMANCE_INFO_GET
#define PSF_EVENT_FLAGS_PERFORMANCE_INFO_GET_FAILED					TX_TRACE_EVENT_FLAGS_PERFORMANCE_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_FLAGS__PERFORMANCE_SYSTEM_INFO_GET_SUCCESS		TX_TRACE_EVENT_FLAGS__PERFORMANCE_SYSTEM_INFO_GET
#define PSF_EVENT_FLAGS__PERFORMANCE_SYSTEM_INFO_GET_FAILED			TX_TRACE_EVENT_FLAGS__PERFORMANCE_SYSTEM_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_FLAGS_SET_SUCCESS            	        			TX_TRACE_EVENT_FLAGS_SET
#define PSF_EVENT_FLAGS_SET_FAILED									TX_TRACE_EVENT_FLAGS_SET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_FLAGS_SET_NOTIFY_SUCCESS	       			     	TX_TRACE_EVENT_FLAGS_SET_NOTIFY
#define PSF_EVENT_FLAGS_SET_NOTIFY_FAILED							TX_TRACE_EVENT_FLAGS_SET_NOTIFY + PSF_EVENT_S1_OFFSET

#define PSF_EVENT_MUTEX_CREATE_SUCCESS								TX_TRACE_MUTEX_CREATE
#define PSF_EVENT_MUTEX_CREATE_FAILED								TX_TRACE_MUTEX_CREATE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_MUTEX_DELETE_SUCCESS								TX_TRACE_MUTEX_DELETE
#define PSF_EVENT_MUTEX_DELETE_FAILED								TX_TRACE_MUTEX_DELETE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_MUTEX_GET_SUCCESS									TX_TRACE_MUTEX_GET + PSF_EVENT_S2_OFFSET
#define PSF_EVENT_MUTEX_GET_FAILED									TX_TRACE_MUTEX_GET + PSF_EVENT_S3_OFFSET
#define PSF_EVENT_MUTEX_GET_BLOCKED									TX_TRACE_MUTEX_GET
#define PSF_EVENT_MUTEX_GET_TIMEOUT									1052
#define PSF_EVENT_MUTEX_INFO_GET_SUCCESS							TX_TRACE_MUTEX_INFO_GET
#define PSF_EVENT_MUTEX_INFO_GET_FAILED								TX_TRACE_MUTEX_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_MUTEX_PERFORMANCE_INFO_GET_SUCCESS				TX_TRACE_MUTEX_PERFORMANCE_INFO_GET
#define PSF_EVENT_MUTEX_PERFORMANCE_INFO_GET_FAILED					TX_TRACE_MUTEX_PERFORMANCE_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_MUTEX_PERFORMANCE_SYSTEM_INFO_GET_SUCCESS			TX_TRACE_MUTEX_PERFORMANCE_SYSTEM_INFO_GET
#define PSF_EVENT_MUTEX_PERFORMANCE_SYSTEM_INFO_GET_FAILED			TX_TRACE_MUTEX_PERFORMANCE_SYSTEM_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_MUTEX_PRIORITIZE_SUCCESS							TX_TRACE_MUTEX_PRIORITIZE
#define PSF_EVENT_MUTEX_PRIORITIZE_FAILED							TX_TRACE_MUTEX_PRIORITIZE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_MUTEX_PUT_SUCCESS									TX_TRACE_MUTEX_PUT
#define PSF_EVENT_MUTEX_PUT_FAILED									TX_TRACE_MUTEX_PUT + PSF_EVENT_S1_OFFSET

#define PSF_EVENT_QUEUE_CREATE_SUCCESS								TX_TRACE_QUEUE_CREATE
#define PSF_EVENT_QUEUE_CREATE_FAILED								TX_TRACE_QUEUE_CREATE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_QUEUE_DELETE_SUCCESS								TX_TRACE_QUEUE_DELETE
#define PSF_EVENT_QUEUE_DELETE_FAILED								TX_TRACE_QUEUE_DELETE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_QUEUE_FLUSH_SUCCESS								TX_TRACE_QUEUE_FLUSH
#define PSF_EVENT_QUEUE_FLUSH_FAILED								TX_TRACE_QUEUE_FLUSH + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_QUEUE_FRONT_SEND_SUCCESS							TX_TRACE_QUEUE_FRONT_SEND + PSF_EVENT_S2_OFFSET
#define PSF_EVENT_QUEUE_FRONT_SEND_FAILED							TX_TRACE_QUEUE_FRONT_SEND + PSF_EVENT_S3_OFFSET
#define PSF_EVENT_QUEUE_FRONT_SEND_BLOCKED							TX_TRACE_QUEUE_FRONT_SEND
#define PSF_EVENT_QUEUE_FRONT_SEND_TIMEOUT							1063
#define PSF_EVENT_QUEUE_INFO_GET_SUCCESS							TX_TRACE_QUEUE_INFO_GET
#define PSF_EVENT_QUEUE_INFO_GET_FAILED								TX_TRACE_QUEUE_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_QUEUE_PERFORMANCE_INFO_GET_SUCCESS				TX_TRACE_QUEUE_PERFORMANCE_INFO_GET
#define PSF_EVENT_QUEUE_PERFORMANCE_INFO_GET_FAILED					TX_TRACE_QUEUE_PERFORMANCE_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_QUEUE_PERFORMANCE_SYSTEM_INFO_GET_SUCCESS			TX_TRACE_QUEUE_PERFORMANCE_SYSTEM_INFO_GET
#define PSF_EVENT_QUEUE_PERFORMANCE_SYSTEM_INFO_GET_FAILED			TX_TRACE_QUEUE_PERFORMANCE_SYSTEM_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_QUEUE_PRIORITIZE_SUCCESS							TX_TRACE_QUEUE_PRIORITIZE
#define PSF_EVENT_QUEUE_PRIORITIZE_FAILED							TX_TRACE_QUEUE_PRIORITIZE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_QUEUE_RECEIVE_SUCCESS								TX_TRACE_QUEUE_RECEIVE + PSF_EVENT_S2_OFFSET
#define PSF_EVENT_QUEUE_RECEIVE_FAILED								TX_TRACE_QUEUE_RECEIVE + PSF_EVENT_S3_OFFSET
#define PSF_EVENT_QUEUE_RECEIVE_BLOCKED								TX_TRACE_QUEUE_RECEIVE
#define PSF_EVENT_QUEUE_RECEIVE_TIMEOUT								1068
#define PSF_EVENT_QUEUE_SEND_NOTIFY_SUCCESS							TX_TRACE_QUEUE_SEND_NOTIFY
#define PSF_EVENT_QUEUE_SEND_NOTIFY_FAILED							TX_TRACE_QUEUE_SEND_NOTIFY + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_QUEUE_SEND_SUCCESS								TX_TRACE_QUEUE_SEND + PSF_EVENT_S2_OFFSET
#define PSF_EVENT_QUEUE_SEND_FAILED									3069
#define PSF_EVENT_QUEUE_SEND_BLOCKED								TX_TRACE_QUEUE_SEND
#define PSF_EVENT_QUEUE_SEND_TIMEOUT								1069

#define PSF_EVENT_SEMAPHORE_CREATE_SUCCESS							TX_TRACE_SEMAPHORE_CREATE
#define PSF_EVENT_SEMAPHORE_CREATE_FAILED							TX_TRACE_SEMAPHORE_CREATE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_SEMAPHORE_CEILING_PUT_SUCCESS						TX_TRACE_SEMAPHORE_CEILING_PUT + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_SEMAPHORE_CEILING_PUT_FAILED						TX_TRACE_SEMAPHORE_CEILING_PUT + PSF_EVENT_S2_OFFSET
#define PSF_EVENT_SEMAPHORE_CEILING_PUT_BLOCKED						TX_TRACE_SEMAPHORE_CEILING_PUT
#define PSF_EVENT_SEMAPHORE_DELETE_SUCCESS							TX_TRACE_SEMAPHORE_DELETE
#define PSF_EVENT_SEMAPHORE_DELETE_FAILED							TX_TRACE_SEMAPHORE_DELETE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_SEMAPHORE_GET_SUCCESS								TX_TRACE_SEMAPHORE_GET + PSF_EVENT_S2_OFFSET
#define PSF_EVENT_SEMAPHORE_GET_FAILED								TX_TRACE_SEMAPHORE_GET + PSF_EVENT_S3_OFFSET
#define PSF_EVENT_SEMAPHORE_GET_BLOCKED								TX_TRACE_SEMAPHORE_GET
#define PSF_EVENT_SEMAPHORE_GET_TIMEOUT								1083
#define PSF_EVENT_SEMAPHORE_INFO_GET_SUCCESS						TX_TRACE_SEMAPHORE_INFO_GET
#define PSF_EVENT_SEMAPHORE_INFO_GET_FAILED							TX_TRACE_SEMAPHORE_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_SEMAPHORE_PERFORMANCE_INFO_GET_SUCCESS			TX_TRACE_SEMAPHORE_PERFORMANCE_INFO_GET
#define PSF_EVENT_SEMAPHORE_PERFORMANCE_INFO_GET_FAILED				TX_TRACE_SEMAPHORE_PERFORMANCE_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_SEMAPHORE__PERFORMANCE_SYSTEM_INFO_GET_SUCCESS	TX_TRACE_SEMAPHORE__PERFORMANCE_SYSTEM_INFO_GET
#define PSF_EVENT_SEMAPHORE__PERFORMANCE_SYSTEM_INFO_GET_FAILED		TX_TRACE_SEMAPHORE__PERFORMANCE_SYSTEM_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_SEMAPHORE_PRIORITIZE_SUCCESS						TX_TRACE_SEMAPHORE_PRIORITIZE
#define PSF_EVENT_SEMAPHORE_PRIORITIZE_FAILED						TX_TRACE_SEMAPHORE_PRIORITIZE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_SEMAPHORE_PUT_NOTIFY_SUCCESS						TX_TRACE_SEMAPHORE_PUT_NOTIFY
#define PSF_EVENT_SEMAPHORE_PUT_NOTIFY_FAILED						TX_TRACE_SEMAPHORE_PUT_NOTIFY + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_SEMAPHORE_PUT_SUCCESS								TX_TRACE_SEMAPHORE_PUT
#define PSF_EVENT_SEMAPHORE_PUT_FAILED								TX_TRACE_SEMAPHORE_PUT + PSF_EVENT_S1_OFFSET

#define PSF_EVENT_THREAD_SYSTEM_RESUME_SUCCESS						1001
#define PSF_EVENT_THREAD_SYSTEM_SUSPEND_SUCCESS						1002
#define PSF_EVENT_THREAD_CREATE_SUCCESS								TX_TRACE_THREAD_CREATE
#define PSF_EVENT_THREAD_CREATE_FAILED								TX_TRACE_THREAD_DELETE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_DELETE_SUCCESS								TX_TRACE_THREAD_DELETE
#define PSF_EVENT_THREAD_DELETE_FAILED								TX_TRACE_THREAD_DELETE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_ENTRY_EXIT_NOTIFY_SUCCESS					TX_TRACE_THREAD_ENTRY_EXIT_NOTIFY
#define PSF_EVENT_THREAD_ENTRY_EXIT_NOTIFY_FAILED					TX_TRACE_THREAD_ENTRY_EXIT_NOTIFY + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_IDENTIFY									TX_TRACE_THREAD_IDENTIFY
#define PSF_EVENT_THREAD_INFO_GET_SUCCESS							TX_TRACE_THREAD_INFO_GET
#define PSF_EVENT_THREAD_INFO_GET_FAILED							TX_TRACE_THREAD_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_PERFORMANCE_INFO_GET_SUCCESS				TX_TRACE_THREAD_PERFORMANCE_INFO_GET
#define PSF_EVENT_THREAD_PERFORMANCE_INFO_GET_FAILED				TX_TRACE_THREAD_PERFORMANCE_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_PERFORMANCE_SYSTEM_INFO_GET_SUCCESS		TX_TRACE_THREAD_PERFORMANCE_SYSTEM_INFO_GET
#define PSF_EVENT_THREAD_PERFORMANCE_SYSTEM_INFO_GET_FAILED			TX_TRACE_THREAD_PERFORMANCE_SYSTEM_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_PREEMPTION_CHANGE_SUCCESS					TX_TRACE_THREAD_PREEMPTION_CHANGE
#define PSF_EVENT_THREAD_PREEMPTION_CHANGE_FAILED					TX_TRACE_THREAD_PREEMPTION_CHANGE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_PRIORITY_CHANGE_SUCCESS					TX_TRACE_THREAD_PRIORITY_CHANGE
#define PSF_EVENT_THREAD_PRIORITY_CHANGE_FAILED						TX_TRACE_THREAD_PRIORITY_CHANGE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_RELINQUISH									TX_TRACE_THREAD_RELINQUISH
#define PSF_EVENT_THREAD_RESET_SUCCESS								TX_TRACE_THREAD_RESET
#define PSF_EVENT_THREAD_RESET_FAILED								TX_TRACE_THREAD_RESET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_RESUME_SUCCESS								TX_TRACE_THREAD_RESUME_API
#define PSF_EVENT_THREAD_RESUME_FAILED								TX_TRACE_THREAD_RESUME_API + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_SLEEP_SUCCESS								TX_TRACE_THREAD_SLEEP
#define PSF_EVENT_THREAD_SLEEP_FAILED								TX_TRACE_THREAD_SLEEP + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_SLEEP_BLOCKED								TX_TRACE_THREAD_SLEEP + PSF_EVENT_S2_OFFSET
#define PSF_EVENT_THREAD_STACK_ERROR_NOTIFY							TX_TRACE_THREAD_STACK_ERROR_NOTIFY
#define PSF_EVENT_THREAD_SUSPEND_SUCCESS							TX_TRACE_THREAD_SUSPEND_API
#define PSF_EVENT_THREAD_SUSPEND_FAILED								TX_TRACE_THREAD_SUSPEND_API + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_TERMINATE_SUCCESS							TX_TRACE_THREAD_TERMINATE
#define PSF_EVENT_THREAD_TERMINATE_FAILED							TX_TRACE_THREAD_TERMINATE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_TIME_SLICE									TX_TRACE_TIME_SLICE
#define PSF_EVENT_THREAD_TIME_SLICE_CHANGE_SUCCESS					TX_TRACE_THREAD_TIME_SLICE_CHANGE
#define PSF_EVENT_THREAD_TIME_SLICE_CHANGE_FAILED					TX_TRACE_THREAD_TIME_SLICE_CHANGE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_THREAD_WAIT_ABORT_SUCCESS							TX_TRACE_THREAD_WAIT_ABORT
#define PSF_EVENT_THREAD_WAIT_ABORT_FAILED							TX_TRACE_THREAD_WAIT_ABORT + PSF_EVENT_S1_OFFSET

#define PSF_EVENT_TIME_GET_SUCCESS									TX_TRACE_TIME_GET
#define PSF_EVENT_TIME_SET_SUCCESS									TX_TRACE_TIME_SET
#define PSF_EVENT_TIMER_CREATE_SUCCESS								TX_TRACE_TIMER_CREATE
#define PSF_EVENT_TIMER_CREATE_FAILED								TX_TRACE_TIMER_CREATE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_TIMER_DELETE_SUCCESS								TX_TRACE_TIMER_DELETE
#define PSF_EVENT_TIMER_DELETE_FAILED								TX_TRACE_TIMER_DELETE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_TIMER_DEACTIVATE_SUCCESS							TX_TRACE_TIMER_DEACTIVATE
#define PSF_EVENT_TIMER_DEACTIVATE_FAILED							TX_TRACE_TIMER_DEACTIVATE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_TIMER_INFO_GET_SUCCESS							TX_TRACE_TIMER_INFO_GET
#define PSF_EVENT_TIMER_INFO_GET_FAILED								TX_TRACE_TIMER_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_TIMER_PERFORMANCE_INFO_GET_SUCCESS				TX_TRACE_TIMER_PERFORMANCE_INFO_GET
#define PSF_EVENT_TIMER_PERFORMANCE_INFO_GET_FAILED					TX_TRACE_TIMER_PERFORMANCE_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_TIMER_PERFORMANCE_SYSTEM_INFO_GET_SUCCESS			TX_TRACE_TIMER_PERFORMANCE_SYSTEM_INFO_GET
#define PSF_EVENT_TIMER_PERFORMANCE_SYSTEM_INFO_GET_FAILED			TX_TRACE_TIMER_PERFORMANCE_SYSTEM_INFO_GET + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_TIMER_CHANGE_SUCCESS								TX_TRACE_TIMER_CHANGE
#define PSF_EVENT_TIMER_CHANGE_FAILED								TX_TRACE_TIMER_CHANGE + PSF_EVENT_S1_OFFSET
#define PSF_EVENT_TIMER_ACTIVATE_SUCCESS							TX_TRACE_TIMER_ACTIVATE
#define PSF_EVENT_TIMER_ACTIVATE_FAILED								TX_TRACE_TIMER_ACTIVATE + PSF_EVENT_S1_OFFSET

#define PSF_EVENT_ISR_BEGIN											4010
#define PSF_EVENT_ISR_RESUME										4011
#define PSF_EVENT_TASK_ACTIVATE										4016
#define PSF_EVENT_TASK_POTENTIAL_SWITCH								4016
#define PSF_EVENT_TASK_POTENTIAL_SWITCH_RESULT						4017
#define PSF_EVENT_UNUSED_STACK										4020
#define PSF_EVENT_USER_EVENT										4030
#define PSF_EVENT_USER_EVENT_FIXED									4038

#define PSF_EVENT_RUNNABLE_REGISTER									4040
#define PSF_EVENT_RUNNABLE_START									4041
#define PSF_EVENT_RUNNABLE_STOP										4042

#define PSF_EVENT_DEPENDENCY_REGISTER								4043

#define TRC_EVENT_LAST_ID											4096

/* Assign recorder defaults to match ThreadX mappings. */
#define PSF_EVENT_TASK_READY										PSF_EVENT_THREAD_SYSTEM_RESUME_SUCCESS
#define PSF_EVENT_TASK_CREATE										PSF_EVENT_THREAD_CREATE_SUCCESS
#define PSF_EVENT_TASK_PRIORITY										PSF_EVENT_THREAD_PRIORITY_CHANGE_SUCCESS

#ifdef __cplusplus
}
#endif /* C++ */

#endif /* TRC_KERNEL_PORT_H */
